﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace CSMF.Management.Page_HollywoodPic
{
    public partial class Pic_List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["admin"] != null)
                {
                    BindDataForGridView();
                }
                else
                {
                    Response.Write("<script language='javascript'>parent.location.href='../login.aspx';</script>");
                }
            }
        }

        private void BindDataForGridView()
        {
            IList<HollywoodPic> log = HollywoodPicManager.GetAllHollywoodPics();
            this.AspNetPager1.RecordCount = log.Count;
            this.AspNetPager1.PageSize = 20;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = log;
            pds.AllowPaging = true;
            pds.PageSize = 20;
            pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
            gvPhoto.DataSource = pds;
            gvPhoto.DataBind();
        }

        protected void gvPhoto_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            LinkButton deleteButton = this.gvPhoto.Rows[e.RowIndex].FindControl("lbDelete") as LinkButton;
            int id = Convert.ToInt32(deleteButton.CommandArgument);
            HollywoodPicManager.DeleteHollywoodPicByID(id);

            BindDataForGridView();
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            BindDataForGridView();
        }
    }
}
